package com.clstu.homeworks;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class HomeWork02 {
    public static void main(String[] args) {
        List list=new ArrayList();
        Car car=new Car("奔驰",280000);
        Car car1=new Car("宝马",350000);
        list.add(car);
        list.add(car1);
        System.out.println(list);
        list.remove(car1);
        System.out.println(list);
        System.out.println(list.contains(car));
        System.out.println(list.contains(car1));
        System.out.println("list 元素个数 "+list.size());
        System.out.println(list.isEmpty());
        list.remove(car);
        System.out.println(list.isEmpty());
        List list1 = new ArrayList();
        list1.add(car);
        list1.add(car1);
        list1.add(car);
        list1.add(car1);
        list.addAll(list1);
        System.out.println(list1);
        list.removeAll(list1);
        System.out.println(list);
        list.addAll(list1);
        list1.clear();//清空
        System.out.println(list1);
        System.out.println("========for=======");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("=========iterator========");
        Iterator iterator=list.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }
        System.out.println("========foreach=======");
        for (Object o:
                list
             ) {
            System.out.println(o);
        }

    }
}
class Car{
    private String name;
    private double price;
    public Car(String name,double price){
        this.name=name;
        this.price=price;
    }

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}